/**
 * 
 */
package sg.edu.nus.iss.vmcs.payment;

import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import sg.edu.nus.iss.vmcs.store.CashStore;

public class CoinInputBoxListener implements ActionListener {

	private CoinReceiver coinReceiver = null;

	public CoinInputBoxListener(CoinReceiver coinReceiver) {
		this.coinReceiver = coinReceiver;
	}

	public void actionPerformed(ActionEvent e) {
		Button btn = (Button) e.getSource();
		String cmd = btn.getActionCommand();
		if (cmd.equalsIgnoreCase(CashStore.COIN_RECEIVER_CLEAR_ERR)) {
			coinReceiver.setError(false);
		} else if (cmd.equalsIgnoreCase(CashStore.COIN_RECEIVER_ERR)) {
			coinReceiver.setError(true);
		} else {
			double weight = Double.parseDouble(cmd);
			coinReceiver.receiveCoin(weight);
		}
	}
}
